package com.hongshan.wallet.core.home

import android.app.Application
import android.databinding.ObservableField
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.bean.PaymentMethod
import com.hongshan.wallet.http.HttpClient
import com.hongshan.wallet.tryRun
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch


/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.home
 * @author   : zhangxx
 * @date     : 2019/3/27
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */
class PayMethodViewModel(application: Application) : MyViewModel(application) {

    var payment_method = ObservableField<List<PaymentMethod>>()

    fun getTopUpInfo() {
        showLoading.call()
        GlobalScope.launch(Dispatchers.Main) {
            val net = GlobalScope.async(Dispatchers.IO) {
                tryRun { HttpClient.httpApi.topUpPageInfo().execute() }
            }
            val response = net.await()
            val result = response?.body()
            showSuccess.call()
            if (result?.code==0){
                 payment_method.set(result.data.payment_method)
            }
        }
    }
}